

$(function(){

    $.mask.definitions['p'] = "[aApP]";
    $.mask.definitions['m'] = "[mM]";
    $.mask.definitions['h'] = "[A-Fa-f0-9]";
    
    $("#time").mask("99:99 pm");
    $("#slash-date").mask("99/99/9999");
    $("#dash-date").mask("99-99-9999");
    $("#datetime").mask("99-99-9999 99:99 pm");
    $("#hex").mask("#hhhhhh");
    $("#product-key").mask("****-****-****-****");
    
    var rules = {};

    rules['time']                  = set_rules('time', 'time', 'required|valid_12hr_time|maxlength[8]');
    rules['slash-date']            = set_rules('slash-date', 'slash-date', 'required|valid_slash_date|maxlength[10]');
    rules['dash-date']             = set_rules('dash-date', 'dash-date', 'required|valid_dash_date|maxlength[10]');
    rules['datetime']              = set_rules('time', 'time', 'required|valid_dash_datetime|maxlength[20]');
    rules['hex']                   = set_rules('time', 'time', 'required|valid_hex_color|maxlength[7]');
    rules['product-key']           = set_rules('product-key', 'product-key', 'required|maxlength[19]');

    // Validation
    $("#masked-validation").validate({
        errorElement: 'small',
        errorClass: 'help-block',
        rules: rules,
        errorPlacement:function(error, element) {
            element.parents('.input-size').append( '<div class="clear-fix"></div>' );
            element.parents('.input-size').append( error);
        },
        highlight: function(label) {
            $(label).closest('.form-group').removeClass('has-error has-success').addClass('has-error');
        },
        success: function(label) {
            label.addClass('valid').closest('.form-group').removeClass('has-error has-success').addClass('has-success');
        }
    });

});